﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Json2Hsm
{
    public class JsonMachine
    {
        public string[] subStates { get; set; }
        public string[] subStateMachines { get; set; }
        public string name { get; set; }
    }
    public class JsonSubMachine:JsonMachine
    {
        public string upStateMachine;
    }

    enum ParamType
    {
        bool_type = 1,
        num_type = 2,
        trigger = 3,
        auto_trigger = 4,
    }
    public class JsonConditions
    {
        public string param { get; set; }
        public int value;
        public int logic;
    }
    public class JsonParam
    {
        public string param { get; set; }
        public int type { get; set; }
        public int init {  get; set; }
    }
    public class JsonTrans
    {
        public string toState {  get; set; }
        public JsonConditions[] conditions { get; set; }
    }
    public class JsonState
    {
        public string upStateMachine { get; set; }
        public string state { get;set; }
        public JsonTrans[] transitions { get; set; }
    }
    public class JsonAnyState
    {
        public JsonTrans[] transitions;
    }
    public class AllJsonMachines
    {
        public JsonMachine mainStateMachine { get; set; }
        public JsonSubMachine[] subStateMachines { get; set; }
        public string defaultState { get; set; }
        public JsonState[] states { get; set; }
        public JsonParam[] parameters { get; set; }
        public JsonAnyState anyState { get; set; }
    }
    
    public class Param
    {
        public string name;
        public int type;
        public int init;
    }
    public class Trans
    {
        public List<Condition> conditions = new List<Condition>();
        public Machine toState;
    }

    public class Condition
    {
        public Param param;
        public int value;
        public int logic;
    }
    
    public class Machine
    {
        private string _name;
        public string name { get { return _name; } set { _name = value; codeName = "fsm_" + value; codeVarName = "var_" + value; funcName = value + "_change_state"; } }
        public List<string> subStates = new List<string>();
        public int depth;
        public string parent;
        public List<Trans> trans = new List<Trans>();
        public string codeName;
        public string codeVarName;
        public string funcName;
    }
}
